<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 */
class Application_Model_Role extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(2)
     *
     * @var int
     */
    protected $_IdRole;

    /**
     * Database var type varchar(50)
     *
     * @var string
     */
    protected $_Description;



    /**
     * Dependent relation fk_enseignant_has_role_role1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_EnseignantRole
     */
    protected $_EnseignantRole;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'id_role'=>'IdRole',
            'description'=>'Description',
        ));

        $this->setParentList(array(
        ));

        $this->setDependentList(array(
            'FkEnseignantHasRoleRole1' => array(
                    'property' => 'EnseignantRole',
                    'table_name' => 'EnseignantRole',
                ),
        ));
    }

    /**
     * Sets column id_role
     *
     * @param int $data
     * @return Application_Model_Role
     */
    public function setIdRole($data)
    {
        $this->_IdRole = $data;
        return $this;
    }

    /**
     * Gets column id_role
     *
     * @return int
     */
    public function getIdRole()
    {
        return $this->_IdRole;
    }

    /**
     * Sets column description
     *
     * @param string $data
     * @return Application_Model_Role
     */
    public function setDescription($data)
    {
        $this->_Description = $data;
        return $this;
    }

    /**
     * Gets column description
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->_Description;
    }

    /**
     * Sets dependent relations fk_enseignant_has_role_role1
     *
     * @param array $data An array of Application_Model_EnseignantRole
     * @return Application_Model_Role
     */
    public function setEnseignantRole(array $data)
    {
        $this->_EnseignantRole = array();

        foreach ($data as $object) {
            $this->addEnseignantRole($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_enseignant_has_role_role1
     *
     * @param Application_Model_EnseignantRole $data
     * @return Application_Model_Role
     */
    public function addEnseignantRole(Application_Model_EnseignantRole $data)
    {
        $this->_EnseignantRole[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_enseignant_has_role_role1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_EnseignantRole
     */
    public function getEnseignantRole($load = true)
    {
        if ($this->_EnseignantRole === null && $load) {
            $this->getMapper()->loadRelated('FkEnseignantHasRoleRole1', $this);
        }

        return $this->_EnseignantRole;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_Role
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_Role());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_Role::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdRole() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('id_role = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdRole()));
    }
}
